import request from '@/utils/request'
import useDictStore from '@/store/modules/dict'

// 查询字典数据详细
function getData(dictCode) {
  return request({
    url: '/task/system/set/list',
    method: 'get',
    params: {codeSystemId: dictCode},
  })
}
export function getOptionByCode(dictCode) {
    const res = ref({});
    return (() => {
        res.value[dictCode] = [];
        const dicts = useDictStore().getDict(dictCode);
        if (dicts) {
          res.value[dictCode] = dicts;
          return dicts
        } else {
            getData(dictCode).then(resp => {
            res.value[dictCode] = resp.rows
            useDictStore().setDict(dictCode, res.value[dictCode]);
            return resp.rows
          })
        }
    })()
  }